/**
 * @author ZhongJiang
 */

/**
 * @function 核对注册信息
 * @returns {boolean}
 */

function checkRegistInfo() {
	if(!checkUserRegistEmail()) {
		alert(ErrorMsgConstants.ERR_PLEASE_CHECK_ALL_REGIST_INPUT);
		return false;
	}
	if(!checkUserRegistNickname()
			|| !checkUserRegistPassword() || !checkUserReRegistPassword()
			|| !checkUserRegistSex() || !checkUserRegistBirthday()) {
		
		alert(ErrorMsgConstants.ERR_PLEASE_CHECK_ALL_REGIST_INPUT);
		
		return false;
	}else {
		if(confirm(ConfirmMsgConstants.CONFIRM_REGIST_FORM_SUBMIT)) {
			return true;
		}else {
			return false;
		}
	}

}


/**
 * @function 核对注册邮箱
 * @returns {Boolean}
 */
function checkUserRegistEmail() {
	var userRegistEmail = $('#userRegistEmail').val();

	if(!validateInput(userRegistEmail,0,50,"E")) {
		$('#userRegistEmailError').html('<font style="color: red;">'+ErrorMsgConstants.ERR_USERID_FORMAT_IS_NOT_VALID+'</font>');
		return false;
	}
	
	var flag = false;
	$.ajax({ 
		url: 'ajaxCheckUserRegistEmailExist.action',
		data: {
			'userRegistEmail':userRegistEmail
		},
		type: 'post',
		async: false,
		dataType: 'json',
		success: function(res) {
			var rs = res.result;
			/*re == 0 表示用户名可用*/
			if(rs != 0) {
				$('#userRegistEmailError').html('<font style="color: red;">'+res.msg+'</font>');
				flag = false;
				return false;
			}else {
				$('#userRegistEmailError').html('<font style="color: green;">'+ValidMsgConstants.VALID_INPUT+'</font>');
				flag = true;
				return true;
			}
		}
	});
	return flag;
}

/**
 * @function 核对注册昵称
 * @returns {Boolean}
 */
function checkUserRegistNickname() {
	var userRegistNickname = $('#userRegistNickname').val();
	if(isEmpty(userRegistNickname)) {
		$('#userRegistNicknameError').html('<font style="color: red;">'+ErrorMsgConstants.ERR_INPUT_IS_NOT_ALLOW_NULL+'</font>');
		return false;
	}
	if(!validateInput(userRegistNickname, 4, 10, "0aA")) {
		$('#userRegistNicknameError').html('<font style="color: red;">'+ErrorMsgConstants.ERR_USERNICKNAME_FORMAT_IS_NOT_VALID+'</font>');
		return false;
	}
	$('#userRegistNicknameError').html('<font style="color: green;">'+ValidMsgConstants.VALID_INPUT+'</font>');
	return true;
}

/**
 * @function 核对注册密码
 * @returns {Boolean}
 */
function checkUserRegistPassword() {
	var userRegistPassword = $('#userRegistPassword').val();
	if(isEmpty(userRegistPassword)) {
		$('#userRegistPasswordError').html('<font style="color: red;">'+ErrorMsgConstants.ERR_INPUT_IS_NOT_ALLOW_NULL+'</font>');
		return false;
	}
	if(!validateInput(userRegistPassword, 6, 10, "0aA")) {
		$('#userRegistPasswordError').html('<font style="color: red;">'+ErrorMsgConstants.ERR_USERPASSWORD_FORMAT_IS_NOT_VALID+'</font>');
		return false;
	}
	$('#userRegistPasswordError').html('<font style="color: green;">'+ValidMsgConstants.VALID_INPUT+'</font>');
	return true;
}

/**
 * @function 核对注册确认密码
 * @returns {Boolean}
 */
function checkUserReRegistPassword() {
	var userRegistPassword = $('#userRegistPassword').val();
	var userReRegistPassword = $('#userReRegistPassword').val();
	
	if(isEmpty(userReRegistPassword)) {
		$('#userReRegistPasswordError').html('<font style="color: red;">'+ErrorMsgConstants.ERR_INPUT_IS_NOT_ALLOW_NULL+'</font>');
		return false;
	}
	if(userRegistPassword != userReRegistPassword) {
		$('#userReRegistPasswordError').html('<font style="color: red;">'+ErrorMsgConstants.ERR_USERREPASSWORD_IS_NOT_VALID+'</font>');
		return false;
	}
	$('#userReRegistPasswordError').html('<font style="color: green;">'+ValidMsgConstants.VALID_INPUT+'</font>');
	return true;
}

/**
 * @function 核对注册性别
 * @returns {Boolean}
 */
function checkUserRegistSex() {
	var userRegistSex = $('#userRegistSex').val();
	return true;
}

/**
 * @function 核对注册生日
 * @returns {Boolean}
 */
function checkUserRegistBirthday() {
	var userRegistBirthday = $('#userRegistBirthday').val();
	/*
	 * 验证方法
	 */
	return true;
}






/**
 * @function 核对登录信息
 * @returns {Boolean}
 */
function checkLoginInfo() {
	if(!checkUserLoginEmail() || !checkUserLoginPassword()) {
		alert(ErrorMsgConstants.ERR_PLEASE_CHECK_ALL_LOGIN_INPUT);
		return false;
	}else {
		return true;
	}
}


/**
 * @function 核对登录邮箱
 * @returns {Boolean}
 */
function checkUserLoginEmail() {
	var userLoginEmail = $('#userLoginEmail').val();
	if(isEmpty(userLoginEmail)) {
		$('#userLoginEmailError').html('<font style="color: red;">'+ErrorMsgConstants.ERR_INPUT_IS_NOT_ALLOW_NULL+'</font>');
		return false;
	}

	if(!validateInput(userLoginEmail, 0, 50, "E")) {
		$('#userLoginEmailError').html('<font style="color: red;">'+ErrorMsgConstants.ERR_USERID_FORMAT_IS_NOT_VALID+'</font>');
		return false;
	}
	
	$('#userLoginEmailError').html('<font style="color: green;">'+ValidMsgConstants.VALID_INPUT+'</font>');
	return true;
}

/**
 * @function 核对登录密码
 * @returns {Boolean}
 */
function checkUserLoginPassword() {
	var userLoginPassword = $('#userLoginPassword').val();
	if(isEmpty(userLoginPassword)) {
		$('#userLoginPasswordError').html('<font style="color: red;">'+ErrorMsgConstants.ERR_INPUT_IS_NOT_ALLOW_NULL+'</font>');
		return false;
	}
	if(!validateInput(userLoginPassword, 6, 10, "0aA")) {
		$('#userLoginPasswordError').html('<font style="color: red;">'+ErrorMsgConstants.ERR_USERPASSWORD_FORMAT_IS_NOT_VALID+'</font>');
		return false;
	}
	$('#userLoginPasswordError').html('<font style="color: green;">'+ValidMsgConstants.VALID_INPUT+'</font>');
	return true;
}












